!
function(a) {
	a.fn.combo = function(b) {
		if (0 == this.length) {
			return this;
		}
		var d, c = arguments;
		this.each(function() {
			var e = a(this).data("_combo");
			if ("string" == typeof b) {
				if (!e) {
					return;
				}
				if ("function" == typeof e[b]) {
					c = Array.prototype.slice.call(c, 1);
					d = e[b].apply(e, c);
				}
			} else {
				if (!e) {
					e = new a.Combo(a(this), b);
					a(this).data("_combo", e);
				}
			}
		});
		return void 0 === d ? this : d;
	};
	a.fn.getCombo = function() {
		return a.Combo.getCombo(this);
	};
	a.Combo = function(b, c) {
		this.obj = b;
		this.opts = a.extend(!0, {}, a.Combo.defaults, c);
		this.dataOpt = this.opts.data;
		this._selectedIndex = -1;
		this._disabled = "undefined" != typeof this.opts.disabled ? !! this.opts.disabled : !! this.obj.attr("disabled");
		a.extend(this, this.opts.callback);
		this._init();
	};
	a.Combo.getCombo = function(b) {
		b = a(b);
		if (0 != b.length) {
			if (1 == b.length) {
				return b.data("_combo");
			}
			if (b.length > 1) {
				var c = [];
				b.each(function() {
					c.push(a(this).data("_combo"));
				});
				return c;
			}
		}
	};
	a.Combo.prototype = {
		constructor: a.Combo,
		_init: function() {
			var b = this.opts;
			if ("select" == this.obj[0].tagName.toLowerCase()) {
				this.originSelect = this.obj;
				this.dataOpt = this._getDataFromSelect();
			}
			this._createCombo();
			this.loadData(this.dataOpt, b.defaultSelected, b.defaultFlag);
			this._handleDisabled(this._disabled);
			this._bindEvent();
		},
		loadData: function(c, b, d) {
			this.xhr && this.xhr.abort();
			this.empty(!1);
			this.dataOpt = c;
			this.mode = this._getRenderMode();
			if (this.mode) {
				if ("local" == this.mode) {
					b = this._formatData();
					this._populateList(this.formattedData);
					this._setDefaultSelected(b, d);
				} else {
					"remote" == this.mode && this._loadAjaxData(b, d);
				}
			}
		},
		activate: function() {
			this.focus || this.input.focus();
			this.wrap.addClass(this.opts.activeCls);
			this.active = !0;
		},
		_blur: function() {
			if (this.active) {
				this.collapse();
				if (this.opts.editable && this.opts.forceSelection) {
					this.selectByText(this.input.val());
				}
				this.wrap.removeClass(this.opts.activeCls);
				this.active = !1;
				"function" == typeof this.onBlur && this.onBlur();
			}
		},
		blur: function() {
			this.focus && this.input.blur();
			this._blur();
		},
		_bindEvent: function() {
			var b = this,
				d = this.opts,
				c = "." + d.listItemCls;
			b.list.on("click", c, function() {
				a(this).hasClass(d.selectedCls) || b.selectByItem(a(this));
				b.collapse();
				b.input.focus();
				"function" == typeof b.onListClick && b.onListClick();
			}).on("mouseover", c, function() {
				a(this).addClass(d.hoverCls).siblings().removeClass(d.hoverCls);
			}).on("mouseleave", c, function() {
				a(this).removeClass(d.hoverCls);
			});
			b.input.on("focus", function() {
				b.wrap.addClass(d.activeCls);
				b.focus = !0;
				b.active = !0;
			}).on("blur", function() {
				b.focus = !1;
			});
			d.editable ? b.input.on("click", function() {
				this.select();
			}) : b.input.on("click", function() {
				b._onTriggerClick();
			});
			b.trigger && b.trigger.on("click", function() {
				b._onTriggerClick();
			});
			a(document).on("click", function(g) {
				var f = g.target || g.srcElement;
				0 == a(f).closest(b.wrap).length && 0 == a(f).closest(b.listWrap).length && b.blur();
			});
			this.listWrap.on("click", function(e) {
				e.stopPropagation();
			});
			a(window).on("resize", function() {
				b._setListPosition();
			});
			this._bindKeyEvent();
		},
		_bindKeyEvent: function() {
			var b = this,
				d = this.opts,
				c = {
					backSpace: 8,
					esc: 27,
					f7: 118,
					up: 38,
					down: 40,
					tab: 9,
					enter: 13,
					home: 36,
					end: 35,
					pageUp: 33,
					pageDown: 34,
					space: 32
				};
			this.input.on("keydown", function(f) {
				switch (f.keyCode) {
				case c.tab:
					b._blur();
					break;
				case c.down:
				case c.up:
					if (b.isExpanded) {
						var e = f.keyCode == c.down ? "next" : "prev";
						b._setItemFocus(e);
					} else {
						b._onTriggerClick();
					}
					f.preventDefault();
					break;
				case c.enter:
					if (b.isExpanded) {
						var g = b.list.find("." + d.hoverCls);
						g.length > 0 && b.selectByItem(g);
						b.collapse();
					}
					break;
				case c.home:
				case c.end:
					if (b.isExpanded) {
						var g = f.keyCode == c.home ? b.list.find("." + d.listItemCls).eq(0) : b.list.find("." + d.listItemCls).filter(":last");
						b._scrollToItem(g);
						f.preventDefault();
					}
					break;
				case c.pageUp:
				case c.pageDown:
					if (b.isExpanded) {
						var e = f.keyCode == c.pageUp ? "up" : "down";
						b._scrollPage(e);
						f.preventDefault();
					}
				}
			}).on("keyup", function(g) {
				if (d.editable) {
					var f = g.which,
						h = 8 == f || 9 == f || 13 == f || 27 == f || f >= 16 && 20 >= f || f >= 33 && 40 >= f || f >= 44 && 46 >= f || f >= 112 && 123 >= f || 144 == f || 145 == f,
						e = b.input.val();
					h && f != c.backSpace || b.doDelayQuery(e);
				}
			});
			a(document).on("keydown", function(e) {
				e.keyCode == c.esc && b.collapse();
			});
		},
		distory: function() {},
		enable: function() {
			this._handleDisabled(!1);
		},
		disable: function(b) {
			b = "undefined" == typeof b ? !0 : !! b;
			this._handleDisabled(b);
		},
		_handleDisabled: function(c) {
			var b = this.opts;
			this._disabled = c;
			1 == c ? this.wrap.addClass(b.disabledCls) : this.wrap.removeClass(b.disabledCls);
			this.input.attr("disabled", c);
		},
		_createCombo: function() {
			var c, f, d, b = this.opts,
				g = parseInt(this.opts.width);
			this.originSelect && this.originSelect.hide();
			if ("input" == this.obj[0].tagName.toLowerCase()) {
				this.input = this.obj;
			} else {
				f = this.obj.find("." + b.inputCls);
				this.input = f.length > 0 ? f : a('<input type="text" class="' + b.inputCls + '"/>');
			}
			this.input.attr({
				autocomplete: "off",
				readOnly: !b.editable
			}).css({
				cursor: b.editable ? "" : "default"
			});
			d = a(this.obj).find("." + b.triggerCls);
			d.length > 0 ? this.trigger = d : b.trigger !== !1 && (this.trigger = a('<span class="' + b.triggerCls + '"></span>'));
			c = this.obj.hasClass(b.wrapCls) ? this.obj : this.obj.find("." + b.wrapCls);
			if (c.length > 0) {
				this.wrap = c.append(this.input, this.trigger);
			} else {
				if (this.trigger) {
					this.wrap = a('<span class="' + b.wrapCls + '"></span>').append(this.input, this.trigger);
					this.originSelect && this.obj[0] == this.originSelect[0] || this.obj[0] == this.input[0] ? this.obj.next().length > 0 ? this.wrap.insertBefore(this.obj.next()) : this.wrap.appendTo(this.obj.parent()) : this.wrap.appendTo(this.obj);
				}
			}
			this.wrap && b.id && this.wrap.attr("id", b.id);
			this.wrap || (this.wrap = this.input);
			this._setComboLayout(g);
			this.list = a("<div />").addClass(b.listCls).css({
				position: "relative",
				overflow: "auto"
			});
			this.listWrap = a("<div />").addClass(b.listWrapCls).attr("id", b.listId).hide().append(this.list).css({
				position: "absolute",
				top: 0,
				zIndex: b.zIndex
			});
			b.extraListHtml && a("<div />").addClass(b.extraListHtmlCls).append(b.extraListHtml).appendTo(this.listWrap);
			if (b.listRenderToBody) {
				a.Combo.allListWrap || (a.Combo.allListWrap = a('<div id="COMBO_WRAP"/>').appendTo("body"));
				this.listWrap.appendTo(a.Combo.allListWrap);
			} else {
				this.wrap.after(this.listWrap);
			}
		},
		_setListLayout: function() {
			var k, g, h = this.opts,
				m = parseInt(h.listHeight),
				j = 0,
				c = this.trigger ? this.trigger.outerWidth() : 0,
				f = parseInt(h.minListWidth),
				d = parseInt(h.maxListWidth);
			this.listWrap.width("auto");
			this.list.height("auto");
			this.listWrap.show();
			this.isExpanded = !0;
			g = this.list.height();
			if (!isNaN(m) && m >= 0) {
				m = Math.min(m, g);
				this.list.height(m);
			}
			if ("auto" == h.listWidth || "auto" == h.width) {
				k = this.listWrap.outerWidth();
				if (g < this.list.height()) {
					j = 20;
					k += j;
				}
			} else {
				k = parseInt(h.listWidth);
				isNaN(k) ? k = this.wrap.outerWidth() : null;
			}
			if ("auto" == h.width) {
				var b = this.listWrap.outerWidth() + Math.max(c, j);
				this._setComboLayout(b);
			}
			f = isNaN(f) ? this.wrap.outerWidth() : Math.max(f, this.wrap.outerWidth());
			!isNaN(f) && f > k && (k = f);
			!isNaN(d) && k > d && (k = d);
			k -= this.listWrap.outerWidth() - this.listWrap.width();
			this.listWrap.width(k);
			this.listWrap.hide();
			this.isExpanded = !1;
		},
		_setComboLayout: function(d) {
			if (d) {
				var c = this.opts,
					g = parseInt(c.maxWidth),
					f = parseInt(c.minWidth);
				!isNaN(g) && d > g && (d = g);
				!isNaN(f) && f > d && (d = f);
				var b;
				d -= this.wrap.outerWidth() - this.wrap.width();
				this.wrap.width(d);
				if (this.wrap[0] != this.input[0]) {
					b = d - (this.trigger ? this.trigger.outerWidth() : 0) - (this.input.outerWidth() - this.input.width());
					this.input.width(b);
				}
			}
		},
		_setListPosition: function() {
			if (this.isExpanded) {
				var q, w, B = (this.opts, a(window)),
					z = this.wrap.offset().top,
					j = this.wrap.offset().left,
					m = B.height(),
					k = B.width(),
					b = B.scrollTop(),
					t = B.scrollLeft(),
					x = this.wrap.outerHeight(),
					y = this.wrap.outerWidth(),
					A = this.listWrap.outerHeight(),
					g = this.listWrap.outerWidth(),
					v = parseInt(this.listWrap.css("border-top-width"));
				q = z - b + x + A > m && z > A ? z - A + v : z + x - v;
				w = j - t + g > k ? j + y - g : j;
				this.listWrap.css({
					top: q,
					left: w
				});
			}
		},
		_getRenderMode: function() {
			var b, c = this.dataOpt;
			a.isFunction(c) && (c = c());
			if (a.isArray(c)) {
				this.rawData = c;
				b = "local";
			} else {
				if ("string" == typeof c) {
					this.url = c;
					b = "remote";
				}
			}
			return b;
		},
		_loadAjaxData: function(d, g, f) {
			var c = this,
				h = c.opts,
				b = h.ajaxOptions,
				j = a("<div />").addClass(h.loadingCls).text(b.loadingText);
			c.list.append(j);
			c.list.find(h.listTipsCls).remove();
			c._setListLayout();
			c._setListPosition();
			c.xhr = a.ajax({
				url: c.url,
				type: b.type,
				dataType: b.dataType,
				timeout: b.timeout,
				cache: false,
				async: b.async,
				success: function(e) {
					j.remove();
					a.isFunction(b.success) && b.success(e);
					a.isFunction(b.formatData) && (e = b.formatData(e));
					if (e) {
						c.rawData = e;
						c._formatData();
						c._populateList(c.formattedData);
						if ("" === d) {
							c.lastQuery = f;
							c.filterData = c.formattedData;
							c.expand();
						} else {
							c._setDefaultSelected(d, g);
						}
						c.xhr = null;
					}
				},
				error: function() {
					j.remove();
					a("<div />").addClass(h.tipsCls).text(b.errorText).appendTo(c.list);
					c.xhr = null;
				}
			});
		},
		getDisabled: function() {
			return this._disabled;
		},
		getValue: function() {
			return this._selectedIndex > -1 ? this.formattedData[this._selectedIndex].value : this.opts.forceSelection ? "" : this.input.val();
		},
		getText: function() {
			return this._selectedIndex > -1 ? this.formattedData[this._selectedIndex].text : this.opts.forceSelection ? "" : this.input.val();
		},
		getSelectedIndex: function() {
			return this._selectedIndex;
		},
		getSelectedRow: function() {
			return this._selectedIndex > -1 ? this.rawData[this._selectedIndex] : void 0;
		},
		getDataRow: function() {
			return this._selectedIndex > -1 ? this.rawData[this._selectedIndex] : void 0;
		},
		getAllData: function() {
			return this.formattedData;
		},
		getAllRawData: function() {
			return this.rawData;
		},
		_setDefaultSelected: function(c, f) {
			var d = this.opts;
			"function" == typeof c && (defaultSelected = defaultSelected.call(this, this.rawData));
			if (isNaN(parseInt(c))) {
				if (a.isArray(c)) {
					this.selectByKey(c[0], c[1], f);
				} else {
					if (this.originSelect) {
						var b = this.originSelect[0].selectedIndex;
						this._setSelected(b, f);
					} else {
						d.autoSelect && this._setSelected(0, f);
					}
				}
			} else {
				var b = parseInt(c);
				this._setSelected(b, f);
			}
		},
		selectByIndex: function(c, b) {
			this._setSelected(c, b);
		},
		selectByText: function(d, c) {
			if (this.formattedData) {
				for (var g = this.formattedData, f = -1, b = 0, h = g.length; h > b; b++) {
					if (g[b].text === d) {
						f = b;
						break;
					}
				}
				this._setSelected(f, c);
			}
		},
		selectByValue: function(d, c) {
			if (this.formattedData) {
				for (var g = this.formattedData, f = -1, b = 0, h = g.length; h > b; b++) {
					if (g[b].value == d) {
						f = b;
						break;
					}
				}
				this._setSelected(f, c);
			}
		},
		selectByKey: function(k, g, h) {
			if (this.rawData) {
				var m = this,
					j = m.opts,
					c = this.rawData,
					f = -1;
				if (j.addOptions) {
					c = this.formattedData;
					for (var d = 0, b = c.length; b > d; d++) {
						if (c[d].value === g) {
							f = d;
							break;
						}
					}
				} else {
					for (var d = 0, b = c.length; b > d; d++) {
						if (c[d][k] === g) {
							f = d;
							break;
						}
					}
				}
				this._setSelected(f, h);
			}
		},
		selectByItem: function(c, b) {
			if (c && c.parent()[0] == this.list[0]) {
				var d = c.text();
				this.selectByText(d, b);
			}
		},
		_setSelected: function(f, d) {
			var h = this.opts,
				f = parseInt(f),
				d = "undefined" != typeof d ? !! d : !0;
			if (!isNaN(f)) {
				if (this.formattedData && 0 != this.formattedData.length) {
					var g = this.formattedData.length;
					(-1 > f || f >= g) && (f = -1);
					if (this._selectedIndex != f) {
						var c = -1 == f ? null : this.formattedData[f],
							j = -1 == f ? null : c.rawData,
							b = -1 == f ? "" : c.text;
						this.list.find("." + h.listItemCls);
						if (!d || "function" != typeof this.beforeChange || this.beforeChange(j)) {
							h.editable && -1 == f && this.focus || this.input.val(b);
							this._selectedIndex = f;
							d && "function" == typeof this.onChange && this.onChange(j);
							this.originSelect && (this.originSelect[0].selectedIndex = f);
						}
					}
				} else {
					this._selectedIndex = -1;
				}
			}
		},
		removeSelected: function(b) {
			this.input.val("");
			this._setSelected(-1, b);
		},
		_triggerCallback: function() {},
		_getDataFromSelect: function() {
			var b = this.opts,
				c = [];
			a.each(this.originSelect.find("option"), function() {
				var e = a(this),
					d = {};
				d[b.text] = e.text();
				d[b.value] = e.attr("value");
				c.push(d);
			});
			return c;
		},
		_formatData: function() {
			if (a.isArray(this.rawData)) {
				var b = this,
					d = b.opts,
					c = d.defaultSelected;
				b.formattedData = [];
				d.emptyOptions && b.formattedData.push({
					text: "(空)",
					value: 0
				});
				d.addOptions && b.formattedData.push(d.addOptions);
				a.each(this.rawData, function(f, e) {
					var g = {};
					g.text = a.isFunction(d.formatText) ? d.formatText(e) : e[d.text];
					g.value = a.isFunction(d.formatValue) ? d.formatValue(e) : e[d.value];
					g.rawData = e;
					b.formattedData.push(g);
					if (e[d.selected] == "1") {
						c = f;
					}
				});
				return c;
			}
		},
		_filter: function(b) {
			b = "undefined" == typeof b ? "" : b.trim();
			this.input.val() != this.getText() && this.selectByText(this.input.val());
			var d = this.opts,
				c = this;
			d.maxFilter;
			if (!this.opts.cache) {
				"local" == this.mode && a.isFunction(this.dataOpt) && (this.rawData = this.dataOpt());
				this._formatData();
			}
			if (a.isArray(this.formattedData)) {
				if ("" == b) {
					this.filterData = this.formattedData;
				} else {
					this.filterData = [];
					a.each(c.formattedData, function(f, h) {
						var e = h.text;
						if (a.isFunction(d.customMatch)) {
							if (!d.customMatch(e, b)) {
								return;
							}
						} else {
							var i = d.caseSensitive ? "" : "i",
								g = new RegExp(b.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), i);
							if (-1 == e.search(g)) {
								return;
							}
						}
						c.filterData.push(h);
						return c.filterData.length == d.maxFilter ? !1 : void 0;
					});
				}
				this.lastQuery = b;
				this.list.empty();
				this._populateList(this.filterData);
				this.expand();
			}
		},
		doDelayQuery: function(c) {
			var b = this,
				f = b.opts,
				d = parseInt(f.queryDelay);
			isNaN(d) && (d = 0);
			b.queryDelay && window.clearTimeout(b.queryDelay);
			b.queryDelay = window.setTimeout(function() {
				b.doQuery(c);
			}, d);
		},
		doQuery: function(b) {
			"local" == this.mode || "remote" == this.mode && this.opts.loadOnce ? this._filter(b) : this._loadAjaxData("", !1, b);
		},
		_populateList: function(d) {
			if (d) {
				var h = this,
					f = h.opts;
				if (0 == d.length) {
					if (f.forceSelection) {
						a("<div />").addClass(f.tipsCls).html(f.noDataText).appendTo(h.list);
						this._setListLayout();
					}
				} else {
					for (var c = 0, j = d.length; j > c; c++) {
						var b = d[c],
							k = b.text,
							g = b.value;
						a("<div />").attr({
							"class": f.listItemCls + (c == this._selectedIndex ? " " + f.selectedCls : ""),
							"data-value": g
						}).text(k).appendTo(h.list);
					}
					this._setListLayout();
				}
			}
		},
		expand: function() {
			var b = this.opts;
			if (this.active && !this.isExpanded && (0 != this.filterData.length || b.noDataText || b.extraListHtmlCls)) {
				this.isExpanded = !0;
				this.listWrap.show();
				this._setListPosition();
				a.isFunction(this.onExpand) && this.onExpand();
				var d = this.list.find("." + b.listItemCls);
				if (0 != d.length) {
					var c = d.filter("." + b.selectedCls);
					0 == c.length && (c = d.eq(0).addClass(b.hoverCls));
					this._scrollToItem(c);
				}
			} else {
				this.listWrap.hide();
			}
		},
		collapse: function() {
			if (this.isExpanded) {
				var b = this.opts;
				this.listWrap.hide();
				this.isExpanded = !1;
				this.listItems && this.listItems.removeClass(b.hoverCls);
				a.isFunction(this.onCollapse) && this.onCollapse();
			}
		},
		_onTriggerClick: function() {
			if (!this._disabled) {
				this.active = !0;
				this.input.focus();
				this.isExpanded ? this.collapse() : this._filter();
			}
		},
		_scrollToItem: function(d) {
			if (d && 0 != d.length) {
				var c = this.list.scrollTop(),
					g = c + d.position().top,
					f = c + this.list.height(),
					b = g + d.outerHeight();
				(c > g || b > f) && this.list.scrollTop(g);
			}
		},
		_scrollPage: function(c) {
			var b, f = this.list.scrollTop(),
				d = this.list.height();
			"up" == c ? b = f - d : "down" == c && (b = f + d);
			this.list.scrollTop(b);
		},
		_setItemFocus: function(d) {
			var c, g, f = this.opts,
				b = this.list.find("." + f.listItemCls);
			if (0 != b.length) {
				var h = b.filter("." + f.hoverCls).eq(0);
				0 == h.length && (h = b.filter("." + f.selectedCls).eq(0));
				if (0 == h.length) {
					c = 0;
				} else {
					c = b.index(h);
					c = "next" == d ? c == b.length - 1 ? 0 : c + 1 : 0 == c ? b.length - 1 : c - 1;
				}
				g = b.eq(c);
				b.removeClass(f.hoverCls);
				g.addClass(f.hoverCls);
				this._scrollToItem(g);
			}
		},
		empty: function() {
			this._setSelected(-1, !1);
			this.input.val("");
			this.list.empty();
			this.rawData = null;
			this.formattedData = null;
		},
		setEdit: function() {}
	};
	a.Combo.defaults = {
		data: null,
		text: "text",
		value: "value",
		selected: "selected",
		formatText: null,
		formatValue: null,
		defaultSelected: void 0,
		defaultFlag: !0,
		autoSelect: !0,
		disabled: void 0,
		editable: !1,
		caseSensitive: !1,
		forceSelection: !0,
		cache: !0,
		queryDelay: 100,
		maxFilter: 10,
		minChars: 0,
		customMatch: customMatch,
		noDataText: "没有匹配的选项",
		width: void 0,
		minWidth: void 0,
		maxWidth: void 0,
		listWidth: void 0,
		listHeight: 150,
		maxListWidth: void 0,
		maxListWidth: void 0,
		zIndex: 1000,
		listRenderToBody: !0,
		extraListHtml: void 0,
		ajaxOptions: {
			type: "post",
			dataType: "json",
			queryParam: "query",
			timeout: 10000,
			formatData: null,
			loadingText: "Loading...",
			success: null,
			error: null,
			errorText: "数据加载失败",
			async: true
		},
		loadOnce: !0,
		id: void 0,
		listId: void 0,
		wrapCls: "ui-combo-wrap",
		focusCls: "ui-combo-focus",
		disabledCls: "ui-combo-disabled",
		activeCls: "ui-combo-active",
		inputCls: "input-txt",
		triggerCls: "trigger",
		listWrapCls: "ui-droplist-wrap",
		listCls: "droplist",
		listItemCls: "list-item",
		selectedCls: "selected",
		hoverCls: "on",
		loadingCls: "loading",
		tipsCls: "tips",
		extraListHtmlCls: "extra-list-ctn",
		callback: {
			onFocus: null,
			onBlur: null,
			beforeChange: null,
			onChange: null,
			onExpand: null,
			onCollapse: null
		}
	};
}(jQuery);

function customMatch(a, e) {
	if (a.indexOf(e) >= 0) {
		return true;
	}
	var c = __pinyin.getPinyin(a);
	if (c.indexOf(e) >= 0) {
		return true;
	}
	var b = __pinyin.getFirstLetter(a);
	if (b.indexOf(e) >= 0) {
		return true;
	}
	var d = __pinyin.getPinyinU(a);
	if (d.indexOf(e) >= 0) {
		return true;
	}
	var f = __pinyin.getFirstLetterU(a);
	if (f.indexOf(e) >= 0) {
		return true;
	}
	return false;
}
